package com.dc.controller;


import com.dc.annotation.Log;
import com.dc.common.ResponseResultVO;
import com.dc.entity.SysResource;
import com.dc.entity.SysRole;
import com.dc.entity.SysUser;
import com.dc.entity.ro.SysRoleRO;
import com.dc.entity.ro.SysRoleResourceRO;
import com.dc.service.SysRoleService;
import com.dc.vo.SysRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统角色
 */
@Api(tags = "后台-角色接口")
@Controller
@RequestMapping(value = "/sys/role")
@RestController
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @Log(title = "系统角色", businessDesc = "新增角色")
    @ApiOperation(value = "新增角色", notes = "新增角色")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResponseResultVO insert(@RequestBody SysRoleRO pageRO) {
        return sysRoleService.insert(pageRO);
    }

    @Log(title = "系统角色", businessDesc = "修改角色")
    @ApiOperation(value = "修改角色", notes = "修改角色")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseResultVO update(@RequestBody SysRoleRO pageRO) {
        return sysRoleService.update(pageRO);
    }

    @ApiOperation(value = "通过角色id查询角色详情", notes = "通过角色id查询角色详情")
    @RequestMapping(value = "/selectRoleById", method = RequestMethod.GET)
    public ResponseResultVO<SysRoleVO> selectRoleById(@RequestParam String id) {
        return sysRoleService.selectRoleById(id);
    }

    @Log(title = "系统角色", businessDesc = "删除角色")
    @ApiOperation(value = "删除角色", notes = "删除角色")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public ResponseResultVO delete(@RequestParam(name = "id") String id) {
        return sysRoleService.delete(id);
    }


    @ApiOperation(value = "查询角色下拉列表", notes = "查询角色下拉列表")
    @RequestMapping(value = "/selectRoleList", method = RequestMethod.GET)
    public ResponseResultVO<SysRole> selectRoleList() {
        return sysRoleService.selectRoleList();
    }

    @ApiOperation(value = "查询角色列表", notes = "查询角色列表")
    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    public ResponseResultVO<SysRole> selectList(@RequestBody SysRoleRO pageRO) {
        return sysRoleService.selectList(pageRO);
    }

    @Log(title = "系统角色", businessDesc = "启动禁用角色")
    @ApiOperation(value = "启动禁用角色", notes = "启动禁用角色")
    @RequestMapping(value = "/updateEnable", method = RequestMethod.POST)
    public ResponseResultVO updateEnable(@RequestBody SysRoleResourceRO ro) {
        return sysRoleService.updateEnable(ro);
    }

    @ApiOperation(value = "查询角色权限列表", notes = "查询角色权限列表")
    @RequestMapping(value = "/selectSysRoleResourceList", method = RequestMethod.GET)
    public ResponseResultVO<SysResource> selectSysRoleResourceList(@RequestParam(name = "id") String id) {
        return sysRoleService.selectSysRoleResourceList(id);
    }

    @ApiOperation(value = "查询角色对应的用户列表", notes = "查询角色对应的用户列表")
    @RequestMapping(value = "/selectUserByRole", method = RequestMethod.GET)
    public ResponseResultVO<SysUser> selectUserByRole(@RequestParam(name = "id") String id) {
        return sysRoleService.selectUserByRole(id);
    }


}
